#!/usr/bin python3
# -*- coding:UTF-8 -*-
# Author: nigo
import plotly.express as px
import pandas as pd
import json

def get_geojson():
    """获取深圳市geojson"""
    with open('深圳市.json') as f:
        text = f.read()
    return json.loads(text)

if __name__ == "__main__":
    # 数据 （随书附件Excel复制后运行）
    df = pd.read_clipboard(delimiter='\s+',thousands=',')
    # 读取geojson数据
    city = get_geojson()
    # 创建Figure对象，（轨迹+画布）
    fig = px.choropleth_mapbox(df,geojson=city, locations='街道',color='交通指数',
                             featureidkey='properties.NAME',color_continuous_scale='Viridis',
                              opacity=0.5,title='深圳交通指数',
                              mapbox_style="carto-positron",
                              zoom=9,center={"lat": 22.555341, "lon": 114.123885})
    # 更新样式 设置画布边界
    fig.update_layout(margin={"r":0,"t":40,"l":0,"b":0})
    # 显示画布
    fig.show()
